// SPDX-License-Identifier: GPL-2.0-only
/*
 * Copyright (c) Huawei Technologies Co., Ltd. 2023-2023. All rights reserved.
 * Author: Huawei OS Kernel Lab
 * Create: Thu Aug 15 16:14:23 2023
 */

#include <linux/kmemleak.h>
#include <linux/proc_fs.h>
#include <trace/hooks/liblinux.h>

static struct proc_ops kmemleak_fops;

static void __init_fops(const struct file_operations *fops)
{
	kmemleak_fops.proc_open = fops->open;
	kmemleak_fops.proc_read = fops->read;
	kmemleak_fops.proc_write = fops->write;
	kmemleak_fops.proc_lseek = fops->llseek;
	kmemleak_fops.proc_release = fops->release;
}

void kmemleak_create_file(const struct file_operations *fops)
{
	struct proc_dir_entry *entry;

	__init_fops(fops);
	entry = proc_create("kmemleak", 0644, NULL, &kmemleak_fops);
	if (!entry)
		pr_warn("create kmemleak file failed\n");
}

/* vendor hook for procfs */
static void hook_kmemleak_create_file(void *__data, const struct file_operations *fops)
{
	kmemleak_create_file(fops);
}
INIT_VENDOR_HOOK(ldk_vh_kmemleak_create_file, hook_kmemleak_create_file);
